<?php

namespace plugin\admin\app\model;

use app\payment\PayFactory;
use plugin\admin\app\model\Base;

/**
 * @property integer $id (主键)
 * @property integer $user_id 用户ID
 * @property integer $source 资产变化类型
 * @property string $type 资产类型
 * @property string $before 变化前余额
 * @property string $amount 变化余额
 * @property string $remark 变化备注
 * @property string $order_no 订单编号
 * @property string $created_time 创建时间
 * @property integer $reward_type 奖励类型,1直推,2间推
 */
class UserPropertyLog extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_user_property_logs';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';
    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;


    const REWARD_OUTCOME = 1;

    const REWARD_INCOME = 2;

    const COIN_GET = 3;

    const EXCHANGE_TO_SD = 4;

    const FROM_SB = 5;

    const FROM_AD = 6;

    const IDENTIFY = 7;

    const PAY_ORDER = 8;

    const ORDER_PAY_BACK = 9;

    const FINISH_PROFILE = 10;

    const REBATE_INTEGRAL_INCOME = 11;

    const REBATE_CONTRIBUTION_INCOME = 12;

    const REBATE_INTEGRAL_TO_UPLINE = 13;

    const SYSTEM_CLEAR_CONTRIBUTION = 14;

    const CONTRIBUTION_TO_BALANCE = 15;

    const EXTRA_REBATE = 16;

    const REBATE_CONTRIBUTION_TO_UPLINE = 17;

    const WITHDRAW = 18;

    const SYSTEM_REDUCE = 19;

    const RECHARGE = 20;

    const INTEGRAL_PAY_ORDER = 21;

    const WITHDRAW_REJECT = 22;

    const INTEGRAL_INCOME_SIGN = 100;

    const BALANCE_RECHARGE = 200;

    const COMMISSION_REBATE_INCOME = 300;

    const TRANSFER_INCOME = 400;

    const TRANSFER_OUTCOME = 500;

    const BIRTHDAY_POINT = 600;

    const INVITE_POINT = 601;

    const REGISTER_POINT = 602;

    const SOURCE_TEXT = [
        self::REWARD_INCOME => '素材被购买佣金',
        self::REWARD_OUTCOME => '打赏',
        self::COIN_GET => '日常收益',
        self::EXCHANGE_TO_SD => '兑换成视点',
        self::FROM_SB => '兑换视点',
        self::FROM_AD => '观看激励广告获得',
        self::IDENTIFY => '实名赠送',
        self::PAY_ORDER => '支付订单',
        self::ORDER_PAY_BACK => '订单退款',
        self::FINISH_PROFILE => '完善资料',
        self::REBATE_INTEGRAL_INCOME => '分享奖励',
        self::REBATE_CONTRIBUTION_INCOME => '购买报单产品赠送贡献值',
        self::REBATE_INTEGRAL_TO_UPLINE => '下级返点积分',
        self::SYSTEM_CLEAR_CONTRIBUTION => '贡献值系统自动清零',
        self::CONTRIBUTION_TO_BALANCE => '贡献值转余额',
        self::EXTRA_REBATE => '直推订单达标额外奖励',
        self::REBATE_CONTRIBUTION_TO_UPLINE => '下级购买报单产品贡献值返点',
        self::WITHDRAW => '提现',
        self::RECHARGE => '系统充值',
        self::SYSTEM_REDUCE => '系统扣除',
        self::INTEGRAL_PAY_ORDER => '积分抵扣',
        self::WITHDRAW_REJECT => '提现驳回',
        self::INTEGRAL_INCOME_SIGN => '签到奖励',
        self::BALANCE_RECHARGE => '余额充值',
        self::COMMISSION_REBATE_INCOME => '下级购买产品返佣',
        self::TRANSFER_INCOME => '积分转入',
        self::TRANSFER_OUTCOME => '积分转出',
        self::BIRTHDAY_POINT => '生日赠送积分',
        self::INVITE_POINT => '拉新送积分',
        self::REGISTER_POINT => '注册赠送积分',
    ];

    const TYPE_TEXT = [
        PayFactory::BALANCE => '积分',
//        PayFactory::INTEGRAL => '积分',
        PayFactory::RECHARGE_BALANCE => '累计充值余额',
        PayFactory::COMMISSION => '佣金'
    ];


    public static function getPayWayText($payWay)
    {
        switch ($payWay) {
            case PayFactory::BALANCE:
                return '积分余额';
            case PayFactory::WECHAT:
                return '微信支付';
            case PayFactory::ALIPAY:
                return '支付宝支付';
        }
    }

    public static function getTypeText($payWay)
    {
        switch ($payWay) {
            case PayFactory::BALANCE:
                return '余额';
            case PayFactory::INTEGRAL:
                return '积分';
            case PayFactory::CONTRIBUTION:
                return '贡献值';
            case PayFactory::RECHARGE_BALANCE:
                return '累计充值余额';
            case PayFactory::COMMISSION:
                return '佣金';
        }
    }

    public static function getSourceText($source)
    {
        return self::SOURCE_TEXT[$source] ?? '其它';
    }
}
